<?php

    require_once "db.php";
    require_once "event_url.php";

    function map_show_regions()
    {
        $locations = db_event_locations(1);
?>
    <script type="text/javascript">
        var $j = jQuery.noConflict();
        $j(function() {
<?php
	if ($locations)
	{
?>
            $j("#map").gMap({ 
		    id: "map1",
		    zoom: 2,
		    markers:
                    [
<?php
	    $x = 0;
	    foreach ($locations as $location)
	    {
		$geocode = explode(" ", $location['geocode']);
            //TODO: check to see if $geocode has more than 1 element
		if ($x)
		    echo ",";
		$x++;
?>
                        {
			    latitude: <?= $geocode[1] ?>,
			    longitude: <?= $geocode[0] ?>,
			    html: '<a href="<?= get_event_url($location['event_id']) ?>" style="text-size: large"> <?= $location['name'] ?> </a>'
			}
<?php
	    }
?>
                    ]
            });
<?php
	}
	else
	{
?>
	    $j("#map").gMap();
<?php
	}
?>
	});
    </script>
    <div id="map" style="width: 620px; height: 400px;"></div>
<?php
    }

    function map_show_location($lat, $long)
    {
?>
    <script type="text/javascript">
        var $j = jQuery.noConflict();
        $j(function() {
            $j("#map").gMap({
		    id: "map1",
		    zoom: 5,
		    markers:[ {
			    latitude: <?= $lat ?>,
			    longitude: <?= $long ?>,
			    html: null
			}]
            });
	});
    </script>
    <div id="map" style="width: 380px; height: 280px;"></div>
<?php
    }


    function test_map()
    {
?>
    <script type="text/javascript">
        var $j = jQuery.noConflict();
        $j(function() {
            $j("#map").gMap();
        });
    </script>
    <div id="map" style="width: 300px; height: 250px;"></div>
<?php
    }

    function map_input($map_id)
    {
?>
    <div id="map" style="width: 600px; height: 400px;"></div>
    <script type="text/javascript">
	function init_input_map()
	{
	    
	    var map_id = "<?= $map_id ?>";

	    $j("#map").gMap({id: map_id});
	 
	    GEvent.addListener(gMap_maps[input_map_id], 'click', function(overlay, point) {
		$j("#map-input-area").dialog("close");
		$j("#event-geocode").val(point.x + " " + point.y);
	    });
	}
    </script>
<?php
    }

?>
